package com.ldc.wandroid.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.ldc.common.common.CommonResultCallback;
import com.ldc.common.model.BaseModel;
import com.ldc.common.model.LoginInfoModel;
import com.ldc.common.mvvm.ViewModelBase;
import com.ldc.common.net.Api2Request;
import com.ldc.wandroid.server.ApiServer;

public class FirstViewModel extends ViewModelBase {
    private final ApiServer apiServer = Api2Request.getInstance().createServer(ApiServer.class);

    private final MutableLiveData<LoginInfoModel> loginInfo = new MutableLiveData<>();

    public LiveData<LoginInfoModel> getLoginInfo() {
        return loginInfo;
    }


    public void login(String username, String password) {
        apiRequest(apiServer.login(username, password), (ok, result, throwable) -> {
            if (ok) {
                loginInfo.setValue(result.getData());
            } else {
                loginInfo.setValue(null);
            }
        });
    }
}
